package com.x.config;

import com.x.interceptor.MyInterceptor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * ClassName: MvcConfig
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2024.09.14 00:43
 */

@Configuration
@ComponentScan("com.x")
@EnableWebMvc
public class MvcConfig implements WebMvcConfigurer {

    //配置jsp地视图解析器
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/WEB-INF/views/",".jsp");
    }

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();//开启静态资源查找
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器

        //方案一：拦截全部请求，执行MyInterceptor类中所有方法
        //registry.addInterceptor(new MyInterceptor());

        //方案二：选择路径拦截, 只拦截选择的请求路径, 也能指定路径排除拦截
        registry.addInterceptor(new MyInterceptor()).addPathPatterns("/order/**").excludePathPatterns("/order/data1");
    }
}
